package cn.huixh.blindbox.controller;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * 基础控制器
 *
 * @author huixh
 * @version 1.0
 * @date 2022/5/13 11:08
 */

public class BaseController {
//14740127419
    /**
     * 响应输出图片文件
     *
     * @param response 响应对象
     * @param imgFile  图片文件
     */
    protected void responseWrite(HttpServletResponse response, File imgFile) {
        try {
            InputStream in = new FileInputStream(imgFile);
            ServletOutputStream out = response.getOutputStream();
            byte[] buffer = new byte[ 1024 ];
            while (in.read(buffer) != -1) {
                out.write(buffer);
            }
            out.flush();
            out.close();
        } catch ( IOException e ) {
            e.printStackTrace();
        }
    }

}
